/**
 * 公共请求地址
 */
var AJAX_URL_USER = "http://localhost:8762/";

/**
 * ajax 封装
 */
function _AJAX(obj) {
    var ajaxObj = {
        headers: {
            Authorization: localStorage.getItem("token")
        },
        url: obj.url,
        type: obj.type,
        contentType: "application/json;charset=utf-8",
        dataType: 'JSON',
        success: function (data) {
    		if(!reqIsSuccess(data)) {
    			layer.msg("操作失败");
    		}
            obj.success(data);
        },
        error: function(error) {
        	layer.msg("操作异常");
        }
    };
    
    if (obj.async === false) ajaxObj.async = false;
    if (obj.data) ajaxObj.data = obj.data;
    if (obj.contentType) ajaxObj.contentType = obj.contentType;

    $.ajax(ajaxObj);
}

/**
 * 请求是否成功 true成功，false失败
 */
function reqIsSuccess(data) {
	if(data.code == 0 || data.code == 200) {
		return true;
	}
	return false;
}

/**
 * 获取URL传的参数
 */
function getRequestValue(key) {
    var url = window.location.search.substring(1);
    var par = url.split('&');
    for (var i = 0; i < par.length; i++) {
        var code = par[i].split('=');
        if (key == code[0]) return code[1];
    }
    return false;
}

/**
 * 错误图片的默认处理
 */
function errimg() {
    $("img").attr('src', "../../img/log9.png");
}